﻿<?php
class Cts_Log_Operation extends Cts_Log
{
	protected $logger ;
	public $aOperationLog ;
	
	public function __construct($db)
	{
	    $this->logger = new Zend_Log();
	    
		// writer
		$writer = new Zend_Log_Writer_Db( $db , 'cts_operation_log' , $this->aOperationLog );
		$this->setOperationLog('0','','') ;
		$this->aOperationLog = array(
            'objName'	=> 'class'  ,
            'funcName'  => 'func',	
            'operator'  => 'operator'    ,
            'ip'        => 'ip'          ,
            'uri'       => 'uri'         ,
            'pid'       => 'pid'         ,
            'time'      => 'timestamp'   ,
            'result'    => 'message'
        );
        
		$writer->setColumnMap( $this->aOperationLog ) ;
		$this->logger->addWriter($writer);
		
		// filter
		$config = Zend_Registry::get('config') ;
		$filter = new Zend_Log_Filter_Priority(intval($config->log->level));
		$this->logger->addFilter($filter);
	}
	
	public function setOperationLog( $nLoginId , $strClassName , $strFuncName )
	{
		$this->setClass( $strClassName ) ;
		$this->setFunc( $strFuncName ) ;
		$this->setOperator( $nLoginId ) ;
		$this->setIP() ;
		$this->setUri() ;
		$this->setPid() ;
	}
	
	private function setOperator( $nLoginId )
	{
		$this->logger->setEventItem( 'operator', $nLoginId ) ;
	}
	
	private function setIP( )
	{
		$this->logger->setEventItem( 'ip', $_SERVER['REMOTE_ADDR'] ) ;
	}
	
	private function setUri( )
	{
	    $this->logger->setEventItem( 'uri' , $_SERVER['REQUEST_URI'] ) ;
	}
	
	private function setPid( )
	{
	    $this->logger->setEventItem( 'pid' , getmypid() ) ;
	}
}